<template>
	<view class="container">
		<view class="top">
			<uni-card margin="15rpx" class="map-card">
				<!-- 顶部进度 -->
				<view class="progress-bar">
					<view class="progress-step">
						<text class="progress-text">预约服务</text>
						<!-- <image src="/static/autoMaintenance/progress-1.png" mode="aspectFit" class="progress-icon"></image> -->
					</view>
					<view class="progress-line"></view>
					<view class="progress-step">
						<text class="progress-text">支付订单</text>
						<!-- <image src="/static/autoMaintenance/progress-2.png" mode="aspectFit" class="progress-icon"></image> -->
					</view>
					<view class="progress-line"></view>
					<view class="progress-step">
						<text class="progress-text">门店服务</text>
						<!-- <image src="/static/autoMaintenance/progress-3.png" mode="aspectFit" class="progress-icon"></image> -->
					</view>
				</view>

				<view class="card-box">
					<!-- 门店信息 -->
					<view class="info">
						<view class="info-left-content">
							<image class="icon" src="/static/autoMaintenance/商家.png" mode="aspectFit"></image>
							<view class="info-content">
								<view class="info-title">{{ receivedSelectedInfo.name }}</view>
								<view class="info-desc">{{ receivedSelectedInfo.address }}</view>
							</view>
						</view>
					</view>
					<!-- 用户信息 -->
					<view class="info">
						<view class="info-left-content">
							<image class="icon" src="/static/autoMaintenance/人员.png" mode="aspectFit"></image>
							<view class="info-label">张先生</view>
						</view>
						<view class="info-value">18656894566</view>
					</view>
					<!-- 预约时间 -->
					<view class="info">
						<uni-datetime-picker :show-icon="false" :border="false" v-model="datetimesingle"
							@change="changeLog" style="margin-left: -10rpx;" />
						<image class="icon" src="/static/autoMaintenance/收起箭头小 拷贝.png" mode="aspectFit"></image>

					</view>
					<!-- 车牌 -->
					<view class="info">
						<view class="info-left-content">
							<image class="icon" src="/static/autoMaintenance/车辆-01.png" mode="aspectFit"></image>
							<view class="info-label">奔驰FWE4/豫A56487</view>
						</view>
						<image class="icon" src="/static/autoMaintenance/收起箭头小 拷贝.png" mode="aspectFit"></image>
					</view>
				</view>

				<!-- 服务产品 -->
				<view class="service-card">
					<view class="service-header">
						<view>服务产品</view>
						<view class="service-count">共选择{{ receivedPackages.length }}项服务产品</view>
					</view>
					<view v-for="(item, idx) in receivedPackages" :key="idx" class="service-item-row">
						<view class="service-item-title">{{ item.name }}</view>
						<view class="service-item-price">￥{{ Number(item.presentPrice).toFixed(1) }}</view>
					</view>
					<view class="coupon-row" @click="goToYouhuiquan">
						<view class="coupon-left-content">
							<image class="icon" src="/static/autoMaintenance/优惠券.png" mode="aspectFit"></image>
							<view class="coupon-label">代金券/优惠券</view>
						</view>
						<image class="icon" src="/static/autoMaintenance/收起箭头小 拷贝.png" mode="aspectFit"></image>
					</view>
				</view>
			</uni-card>
		</view>

		<view class="fixed-bottom-bar">
			<view class="contact-customer-service" @click="showContactModal = true">
				<image class="icon" src="/static/autoMaintenance/客服.png" mode="aspectFit"></image>
				<view class="coupon-label">联系客服</view>
			</view>
			<view class="total-and-button">
				<view class="service-total">
					合计：<text class="service-total-price">￥{{ (Number(receivedTotal)).toFixed(1) }}</text>
				</view>
				<button class="submit-order-button" @click="showPaymentModal = true">提交订单</button>
			</view>
		</view>

		<!-- Contact Customer Service Modal -->
		<view class="contact-modal-overlay" v-if="showContactModal" @click="showContactModal = false">
			<view class="contact-modal-content" @click.stop>
				<view class="phone-number">18642589456</view>
				<view class="modal-action" @click="copyPhoneNumber">复制</view>
				<view class="modal-action" @click="showContactModal = false">取消拨号</view>
			</view>
		</view>

		<!-- Payment Password Modal -->
		<view class="payment-password-modal-overlay" v-if="showPaymentModal" @click="showPaymentModal = false">
			<view class="payment-password-modal-content" @click.stop>
				<view class="modal-header">
					<view class="close-button" @click="showPaymentModal = false">×</view>
					<view class="modal-title">请输入支付密码</view>
					<view class="placeholder"></view>
				</view>

				<view class="payment-details">
					<view class="service-platform">车辆服务平台</view>
					<view class="payment-amount">￥{{ (Number(total)).toFixed(2) }}</view>
				</view>

				<view class="divider-line"></view>

				<view class="payment-method-row">
					<view class="payment-method-label">支付方式</view>
					<view class="payment-method-value">零钱 ></view>
				</view>

				<view class="password-input-area">
					<!-- Simulate password input squares -->
					<input class="password-square-input" type="password" maxlength="1" />
					<input class="password-square-input" type="password" maxlength="1" />
					<input class="password-square-input" type="password" maxlength="1" />
					<input class="password-square-input" type="password" maxlength="1" />
					<input class="password-square-input" type="password" maxlength="1" />
					<input class="password-square-input" type="password" maxlength="1" />
				</view>
			</view>
		</view>

	</view>
</template>

<script setup>
import { ref } from 'vue';
import { onLoad } from '@dcloudio/uni-app';

const receivedPackages = ref([]);
const receivedSelectedInfo = ref(null);
const receivedTotal = ref(0);

// Define the method to navigate to the youhuiquan page
const goToYouhuiquan = () => {
    console.log('Navigate to the coupon page');
    // Use uni.navigateTo directly
    uni.navigateTo({
        url: '/pages/youhuiquan/youhuiquan'
    });
};

onLoad((options) => {
    try {
        if (options.packages) {
            receivedPackages.value = JSON.parse(decodeURIComponent(options.packages));
            // console.log(':', receivedPackages.value);
        }
        if (options.selectedInfo) {
            receivedSelectedInfo.value = JSON.parse(decodeURIComponent(options.selectedInfo));
            // console.log('Store information:', receivedSelectedInfo.value);
        }
        if (options.total) {
            receivedTotal.value = parseFloat(options.total);
            // console.log('Total price:', receivedTotal.value);
        }
    } catch (error) {
        console.error('Data parsing error:', error);
    }
});
</script>

<style>
.container {
	background: #fff;
	min-height: 100vh;
	padding-bottom: 80rpx;
}

.top {
	margin-top: -15rpx;
	padding-top: 20rpx;
	height: 300rpx;
	background-color: #3083fb;
}

.progress-bar {
	display: flex;
	justify-content: center;
	align-items: center;
	padding: 32rpx 0;
}

.progress-step {
	width: 120rpx;
	height: 120rpx;
	border-radius: 50%;
	display: flex;
	justify-content: center;
	align-items: center;
	text-align: center;
	font-size: 24rpx;
}

.progress-step:nth-child(1) {
	background: linear-gradient(to bottom, #56a9f2, #3083fb);
}

.progress-step:nth-child(3) {
	background: linear-gradient(to bottom, #5ee0a0, #30c87d);
}

.progress-step:nth-child(5) {
	background: linear-gradient(to bottom, #ff8d6c, #ff4d4f);
}

.progress-text {
	font-size: 24rpx;
	color: #fff;
	font-weight: 500;
	line-height: 1.2;
}

.progress-line {
	width: 120rpx;
	height: 2rpx;
	border-top: 2rpx dashed #ccc;
	margin: 0 20rpx;
}

.card-box {
	margin-top: 50rpx;
	background: #fff;
	border-radius: 24rpx;
	margin: 0 24rpx 24rpx 24rpx;
	padding: 24rpx 0 0 0;
	box-shadow: 0 2rpx 8rpx 0 rgba(0, 0, 0, 0.03);
}

.info {
	padding: 18rpx 32rpx;
	display: flex;
	align-items: center;
	justify-content: space-between;
}

.info-left-content {
	display: flex;
	align-items: center;
}

.info-content {
	flex: 1;
}

.icon {
	width: 30rpx;
	height: 30rpx;
	margin-right: 16rpx;
}

.info-row {
	display: flex;
	justify-content: space-between;
	align-items: center;
	padding: 18rpx 32rpx;
}

.info-title {
	font-size: 30rpx;
	font-weight: bold;
	color: #222;
}

.info-desc {
	font-size: 24rpx;
	color: #888;
	margin-top: 6rpx;
}

.info-label {
	font-size: 28rpx;
	color: #222;
}

.info-value {
	font-size: 28rpx;
	color: #888;
}

.info-arrow {
	font-size: 32rpx;
	color: #bbb;
}

.service-card {
	background: #fff;
	border-radius: 24rpx;
	margin: 0 24rpx;
	margin-bottom: 24rpx;
	padding: 24rpx 0 0 0;
	box-shadow: 0 2rpx 8rpx 0 rgba(0, 0, 0, 0.03);
	border-top: 1rpx solid #f0f0f0;
}

.service-header {
	display: flex;
	justify-content: space-between;
	align-items: center;
	padding: 18rpx 32rpx;
	font-size: 28rpx;
	font-weight: bold;
	border-bottom: 1rpx solid #f0f0f0;
}

.service-count {
	font-size: 24rpx;
	font-weight: normal;
	color: #3083fb;
}

.service-item-row {
	display: flex;
	justify-content: space-between;
	align-items: center;
	padding: 18rpx 32rpx;
	font-size: 28rpx;
	color: #222;
	border-bottom: 1rpx solid #f0f0f0;
}

.service-item-title {
	flex: 1;
}

.service-item-price {
	color: #ff4d4f;
	font-size: 28rpx;
	font-weight: bold;
	margin-left: 16rpx;
}

.coupon-row {
	display: flex;
	justify-content: space-between;
	align-items: center;
	padding: 18rpx 32rpx;
	font-size: 28rpx;
	color: #222;
}

.coupon-left-content {
	display: flex;
	align-items: center;
}

.coupon-label {
	color: #888;
}

.coupon-value {
	color: #ff4d4f;
}

.service-total-row {
	display: flex;
	justify-content: flex-end;
	align-items: center;
	padding: 18rpx 32rpx;
	font-size: 28rpx;
	color: #222;
}

.service-total {
	font-weight: bold;
}

.service-total-price {
	color: #ff4d4f;
	font-size: 32rpx;
	margin-left: 8rpx;
}

.fixed-bottom-bar {
	position: fixed;
	bottom: 0;
	left: 0;
	right: 0;
	display: flex;
	justify-content: space-between;
	align-items: center;
	padding: 20rpx 32rpx;
	background-color: #fff;
	box-shadow: 0 -2rpx 8rpx 0 rgba(0, 0, 0, 0.03);
}

.contact-customer-service {
	display: flex;
	align-items: center;
	font-size: 28rpx;
	color: #222;
}

.total-and-button {
	display: flex;
	align-items: center;
}

.total-and-button .service-total {
	font-weight: bold;
	color: #222;
	font-size: 28rpx;
	margin-right: 20rpx;
}

.total-and-button .service-total-price {
	color: #ff4d4f;
	font-size: 32rpx;
	margin-left: 8rpx;
}

.submit-order-button {
	background: linear-gradient(to right, #56a9f2, #3083fb);
	color: #fff;
	font-size: 28rpx;
	padding: 8rpx 30rpx;
	border-radius: 40rpx;
	border: none;
	outline: none;
}

/* Contact Modal Styles */
.contact-modal-overlay {
	position: fixed;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	background-color: rgba(0, 0, 0, 0.5);
	display: flex;
	justify-content: center;
	align-items: flex-end;
	/* Align to the bottom */
	z-index: 1000;
}

.contact-modal-content {
	background-color: #fff;
	border-top-left-radius: 20rpx;
	border-top-right-radius: 20rpx;
	width: 100%;
	padding: 0 30rpx;
	padding-bottom: env(safe-area-inset-bottom);
	/* Consider safe area for bottom bar */
}

.phone-number {
	text-align: center;
	font-size: 36rpx;
	font-weight: bold;
	color: #333;
	padding: 30rpx 0;
	border-bottom: 1rpx solid #eee;
}

.modal-action {
	text-align: center;
	font-size: 32rpx;
	color: #3083fb;
	padding: 30rpx 0;
}

.modal-action:first-child {
	border-bottom: 1rpx solid #eee;
}

/* Payment Password Modal Styles */
.payment-password-modal-overlay {
	position: fixed;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	background-color: rgba(0, 0, 0, 0.5);
	display: flex;
	justify-content: center;
	align-items: center;
	/* Center the modal */
	z-index: 1000;
}

.payment-password-modal-content {
	background-color: #fff;
	border-radius: 16rpx;
	width: 80%;
	max-width: 500rpx;
	/* Adjust max-width as needed */
	overflow: hidden;
}

.modal-header {
	display: flex;
	justify-content: space-between;
	align-items: center;
	padding: 20rpx 30rpx;
	border-bottom: 1rpx solid #eee;
}

.close-button {
	font-size: 40rpx;
	color: #999;
	cursor: pointer;
	width: 40rpx;
	text-align: center;
}

.modal-header .modal-title {
	font-size: 32rpx;
	font-weight: bold;
	color: #333;
	flex-grow: 1;
	text-align: center;
}

.placeholder {
	width: 40rpx;
	/* To balance the close button */
}

.payment-details {
	padding: 40rpx 30rpx 20rpx 30rpx;
	text-align: center;
}

.service-platform {
	font-size: 28rpx;
	color: #666;
	margin-bottom: 10rpx;
}

.payment-amount {
	font-size: 48rpx;
	font-weight: bold;
	color: #222;
}

.divider-line {
	height: 1rpx;
	background-color: #eee;
	margin: 0 30rpx;
}

.payment-method-row {
	display: flex;
	justify-content: space-between;
	align-items: center;
	padding: 30rpx;
	font-size: 28rpx;
	color: #333;
}

.payment-method-label {
	color: #666;
}

.payment-method-value {
	color: #3083fb;
}

.password-input-area {
	display: flex;
	justify-content: center;
	padding: 30rpx 30rpx 40rpx 30rpx;
}

.password-square-input {
	width: 60rpx;
	/* Adjust size as needed */
	height: 60rpx;
	/* Adjust size as needed */
	border: 1rpx solid #ccc;
	margin: 0 5rpx;
	text-align: center;
	font-size: 36rpx;
	color: #222;
	box-sizing: border-box;
	/* Include border in element's total width and height */
}
</style>